package com.example.ncpapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.ncpapplication.R;
import com.example.ncpapplication.bean.NCPInfo;
import com.example.ncpapplication.utils.MyListViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class CityActivity extends AppCompatActivity implements View.OnClickListener {

    private List<NCPInfo.NewslistBean> ncpList = new ArrayList<>();
    private List<NCPInfo.NewslistBean.CitiesBean> citiyList = new ArrayList<>();
    private ImageView iv_city_back;
    private TextView tv_city_provinceName;
    private ListView lv_city_list;
    private MyListViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city);
        initView();
        getData();
    }

    private void getData() {
        Intent intent = getIntent();
        int position = Integer.valueOf(intent.getStringExtra("position"));
        ncpList = MainActivity.ncpList;
        tv_city_provinceName.setText(ncpList.get(position).getProvinceName());
        for (int i = 0; i < ncpList.get(position).getCities().size(); i++) {
            citiyList.add(ncpList.get(position).getCities().get(i));
        }
        adapter.notifyDataSetChanged();
    }

    private void initView() {
        iv_city_back = (ImageView) findViewById(R.id.iv_city_back);
        iv_city_back.setOnClickListener(this);
        tv_city_provinceName = (TextView) findViewById(R.id.tv_city_provinceName);
        lv_city_list = (ListView) findViewById(R.id.lv_city_list);
        adapter = new MyListViewAdapter(this, R.layout.city_item_layout, citiyList);
        lv_city_list.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_city_back:
                finish();
                break;
        }
    }
}
